/*    
 * Copyright (c) 2013 ISoftStone, Inc.
 * All right reserved.
 *
 * 文件名：      BusinessLogger.java
 * 作者:     Jacky Wang
 * 创建日期： 2013-7-1 下午08:10:13
 * 版本：           
 *
 */
package com.isoftstone.industry.aaa.core.log;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.isoftstone.industry.aaa.constants.Version;
import com.isoftstone.modules.core.utils.template.ITemplate;

/**
 *
 * @author jacky
 */
@Component("businessLogger")
@Scope("singleton")
public class BusinessLogger
{
	public static final String BEAN_NAME = "businessLogger";
	
	@Resource(name="propTemplate")
	private ITemplate template;
	
	private static final Logger logger = Logger.getLogger("AAABusiness");
	
	private static final Logger errorLogger = Logger.getLogger(BusinessLogger.class);
	
	/**
	 * 用于AAAServer的日志记录:{date}|{level}|{version}|{msg}
	 * @param       
	 * @return     
	 * @throws
	 */
	public void info(String code, Object... args)
	{
		StringBuffer sb = new StringBuffer();
		sb.append(Version.latest().toString());
		sb.append("|");
		String msg = template.processTemplate2String(code, args);
		sb.append(msg);
		logger.info(sb.toString());
	}
	
	public void error(String msg, Throwable thr)
	{
		StringBuffer sb = new StringBuffer();
		sb.append(Version.latest().toString());
		sb.append("|");
		sb.append(msg);
		errorLogger.error(sb.toString(), thr);
	}
}
